package com.gopay.webtest.controller.cbrmb;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Resource;

import com.gopay.webtest.controller.base.BaseController;
import org.apache.log4j.Logger;
import org.dom4j.DocumentException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.handler.Trans7030Handler;
import com.gopay.webtest.vo.ImportInfo;
import com.gopay.webtest.xml.XmlDao;

/**
 * 
 * @ClassName: CbrmbQueryController
 * @Description: 跨境进口查询 交易码：7030
 * @author gd.cui
 * @date 2016年7月14日 下午1:46:26 ww.gopay.com.cn Inc.All rights reserved.
 */
@Controller
@RequestMapping("/cbrmb")
public class CbrmbQueryController extends BaseController {
    @Resource(name = "xmlDao")
    private XmlDao xmlDao = null;
    @Resource(name = "trans7030Handler")
    private Trans7030Handler trans7030Handler;

    private static Logger logger = Logger.getLogger(CbrmbQueryController.class);

    @RequestMapping(method = RequestMethod.GET, value = "/cbrmbQuery")
    public ModelAndView cbrmbQuery() {
        ModelAndView mv = new ModelAndView();
        // 加载xml数据到
        try {
            Map<String, String> map = this.xmlDao.readData4Map("cbrmbquery", "cbrmbinfo");
            mv.addObject("importInfo", map);
            mv.setViewName("gopay.webtest.pay.cbrmbquery");
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return mv;
    }

    @RequestMapping("/cbrmbQuerySubmit")
    public ModelAndView cbrmbQuerySubmit(ImportInfo importInfo) {
        ModelAndView mv = new ModelAndView("gopay.webtest.pay.cbrmbQuerySubmit");
        /*** 对表单数据进行处理 begin */
        try {
            // 进行加签
            trans7030Handler.sign(importInfo.getTranCode() + "_" + importInfo.getVersion(), "signType", "signValue",
                    importInfo, getRequest());
        } catch (Exception e) {
            logger.error("加签出错");
            e.printStackTrace();
        }
        mv.addObject("importInfo", importInfo);
        return mv;
    }
}
